package engine.scene;

import behaviors.Position;
import behaviors.Rotation;
import behaviors.ViewMatrices;
import engine.hw.Screen;

public class Camera3D
{
    
    private Position viewPos;
    //<editor-fold defaultstate="collapsed" desc="getViewPos">
    public Position getViewPos()
    {
        return this.viewPos;
    }
    //</editor-fold>
    
    private Rotation viewRot;
    //<editor-fold defaultstate="collapsed" desc="getViewRot">
    public Rotation getViewRot()
    {
        return this.viewRot;
    }
    //</editor-fold>
    
    private ViewMatrices viewMatrices;
    //<editor-fold defaultstate="collapsed" desc="getViewMatrices">
    public ViewMatrices getViewMatrices()
    {
        return this.viewMatrices;
    }
    //</editor-fold>
    
    public void setUpViewMatrices()
    {
        this.viewMatrices.setMatrixProjTo3D(
            this.fovYDeg, 
            Screen.get().getAspectRatio(), 
            this.zNear, 
            this.zFar
        );
    }
    
    private float zNear;
    //<editor-fold defaultstate="collapsed" desc="setZNear">
    public final void setZNear(float znear)
    {
        this.zNear = znear;
    }
    //</editor-fold>
    
    private float zFar;
    //<editor-fold defaultstate="collapsed" desc="setZFar">
    public final void setZFar(float zfar)
    {
        this.zFar = zfar;
    }
    //</editor-fold>
    
    private float fovYDeg;
    //<editor-fold defaultstate="collapsed" desc="setFOVDeg">
    public final void setFOVDeg(float fovYDegrees)
    {
        this.fovYDeg = fovYDegrees;
    }
    //</editor-fold>
    
    private float tilt;
    //<editor-fold defaultstate="collapsed" desc="setTilt">
    public void setTilt(float value)
    {
        this.tilt = value;
    }
    //</editor-fold>
    //<editor-fold defaultstate="collapsed" desc="addTilt">
    public void addTilt(float deltaValue)
    {
        this.tilt += deltaValue;
    }
    //</editor-fold>
    
    public Camera3D()
    {
        this.viewPos = new Position();
        this.viewPos.setStart(0.0f, 0.0f, 0.0f);
        this.viewRot = new Rotation();
        this.viewRot.setStart(0.0f, 0.0f);
        this.viewMatrices = new ViewMatrices();
        this.tilt = 0.0f;
        this.viewMatrices.setMatrixProjTo3D(
            this.fovYDeg, 
            Screen.get().getAspectRatio(), 
            this.zNear, 
            this.zFar
        );
    }
    
    public void update()
    {
        this.viewMatrices.setMatrixViewTo(
            this.viewPos.getPos(), 
            this.viewRot.getRots()
        );
    }
    
    public void reset()
    {
        this.viewPos.resetToStart();
        this.viewRot.resetRotsToStart();
        this.tilt = 0.0f;
    }
    
    public void destroy()
    {
        this.viewPos = null;
        this.viewRot = null;
        this.tilt = 0.0f;
    }
    
}
